package cn.wolfcode.trip.app.web.controller;

import cn.wolfcode.trip.base.domain.DailyDetail;
import cn.wolfcode.trip.base.query.DailyDetailQueryObject;
import cn.wolfcode.trip.base.service.IDailyDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/dailyDetails")
public class DailyDetailController {
    @Autowired
    private IDailyDetailService dailyDetailService;
    /*
       查询热门的日报文章
       动作:GET
       资源:/dailyDetails/commends
       参数:type=xx
    */
    @GetMapping
    public Object listCommends(DailyDetailQueryObject qo) {
        System.out.println(qo);
        if (qo.getState()==DailyDetail.STATE_COMMON) {
            //设置按照创建时间降序排列
            qo.setPageSize(6);
            qo.setOrderBy("sd.createTime desc");
            return dailyDetailService.query(qo);
        }
        return dailyDetailService.listCommends(qo.getState());
    }

    /**
     * 查询某篇日报的文章内容
     * @return
     */
    @GetMapping("/{id}")
    public Object get(@PathVariable Long id){
        return dailyDetailService.getContent(id);
    }

    /**
     * 查询日报状态为推荐文章
     * @return
     */
    @GetMapping("/commends")
    public Object getCommend(Integer state){
        return dailyDetailService.getCommend(state);
    }

    /**
     * 查询日报状态为更多的文章
     * @return
     */
    @GetMapping("/else")
    public Object getElse(Integer state){
        List<DailyDetail> getelse = dailyDetailService.getelse(state);
        return getelse;
    }


}
